using System;
using System.Collections.Generic;
using System.Text;
using GarageGames.Torque.T2D;
using GarageGames.Torque.Core;
using GarageGames.Torque.Materials;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Sim;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.XNA;
using GarageGames.Torque.TS;

namespace Xyne.Templates
{
    public class PuzzlePulse : T2DAnimatedSprite
    {
        private const int NumberCastCells = 10;
        private static PuzzlePulse template = new PuzzlePulse();

        public static PuzzlePulse Template
        {
            get { return template; }
        }

        public PuzzlePulse()
        {
            // Set the template and name
            IsTemplate = true;
            Name = Game.PuzzlePulseName;

            // Various parameters
            //SimpleMaterial material = new SimpleMaterial();
            //Texture2D texture = TorqueEngineComponent.Instance.Game.Content.Load<Texture2D>(@".\data\images\ui\puzzlepiece\puzzlepiecepulse");
            //material.SetTexture(texture);

            LightingMaterial material = (LightingMaterial)TorqueObjectDatabase.Instance.FindObject<LightingMaterial>("PulseLightMaterial").Clone();

            T2DAnimationData data = new T2DAnimationData();
            CellCountDivider divider = new CellCountDivider();
            divider.CellCountX = NumberCastCells;
            divider.CellCountY = 1;
            material.TextureDivider = divider;
            data.Material = material;
            data.AnimationDuration = 0.5f;
            data.AnimationFrames = "0 1 2 3 4 5 6 7 8 9";
            data.Init();
            AnimationData = data;
            Size = new Vector2(420 / NumberCastCells, 42); // TODO : proper image size
            Layer = Game.PuzzlePulseLayer;
            ObjectType = TorqueObjectDatabase.Instance.GetObjectType(Name);
            RemoveOnFinished = true;
        }

        public override void CopyTo(TorqueObject obj)
        {
            base.CopyTo(obj);

            obj.Name = Game.PuzzlePulseName;
        }
    }
}
